var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIBase"),
    s = t("ShopItemBuyReward1"),
    c = t("GameEm"),
    p = cc._decorator,
    l = p.ccclass,
    d =
        (p.property,
        p.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.checkCost = 0;
                e.itemLast = [];
                e.spriteIcon = [];
                e.parseKey = "20301";
                return e;
            }
            e.prototype.onShowEnd = function () {
                var t = this;
                this.scheduleOnce(function () {
                    t._bgNode.$Animation.play("firstpay");
                });
                GameDataValue.setFirstOpenKey(!0);
                var e = CacheDataManager.getShopDataCof().shop,
                    o = this.parseKey;
                if (e[o]) {
                    var a = e[o];
                    this.checkCost = a.cash;
                    this._costLab.$Label.string = "￥" + this.checkCost;
                    for (var i = a.icon.split("|"), n = a.products.split("|"), r = 0; r < n.length; r++) {
                        var s = n[r];
                        this.viewTagItem(s, r, i, a);
                    }
                } else this.closeUI();
            };
            e.prototype.viewTagItem = function (t, e, o, a) {
                var i = this,
                    n = this.itemLast[e] || QLooperNode.getNode(QLooperNode.tag_shopItemBuyReward1);
                if (n) {
                    n.parent = this._rewardItem;
                    for (
                        var r = n.getComponent(s.default), c = r.setKindData(a, t, o[e], e, 0), p = 0;
                        p < c.length;
                        p++
                    )
                        this.spriteIcon.push({
                            wpos: r.node.convertToWorldSpaceAR(cc.Vec2.ZERO),
                            path: c[p].path,
                            isZb: c[p].isZb,
                            idData: c[p].idData,
                            count: c[p].count
                        });
                    this.itemLast.push(n);
                } else
                    this.scheduleOnce(function () {
                        i.viewTagItem(t, e, o, a);
                    }, 0.1);
            };
            e.prototype.udpatePos = function () {
                for (var t = 0; t < this.itemLast.length; t++)
                    this.spriteIcon[t] &&
                        (this.spriteIcon[t].wpos = this.itemLast[t].convertToWorldSpaceAR(cc.Vec2.ZERO));
            };
            e.prototype.onCloseStart = function () {
                for (var t = 0; t < this.itemLast.length; t++) QLooperNode.putNode(this.itemLast[t]);
            };
            e.prototype._onBuyBtnTouchEnd = function () {
                var t = this;
                if (PayData.checkPayCost(this.checkCost)) {
                    this.udpatePos();
                    EVUIEffView.emit(EVUIEffView.udpateMovePageTime);
                    for (var e = [], o = 0; o < this.spriteIcon.length; o++)
                        if (this.spriteIcon[o].isZb)
                            for (var a = 0; a < this.spriteIcon[o].count; a++)
                                e.push({id: this.spriteIcon[o].idData, num: this.spriteIcon[o].count});
                        else {
                            var i = this.spriteIcon[o].idData;
                            if ("2" == i) e.push({id: 1, num: this.spriteIcon[o].count});
                            else
                                switch (i) {
                                    case "5":
                                    case "6":
                                    case "7":
                                        e.push({id: i, num: this.spriteIcon[o].count});
                                }
                        }
                    PayData.addPayData(
                        this.parseKey,
                        this.checkCost,
                        function (e) {
                            if (e) {
                                PayData.setOverKey("20301", !0);
                                QReport.send("220301");
                                CacheDataManager.getCostumeup();
                                for (
                                    var o = {resId: t.parseKey, count: t.checkCost, type: 2, tip: "首充", tip2: ""},
                                        a = [],
                                        i = 0;
                                    i < t.spriteIcon.length;
                                    i++
                                ) {
                                    var n = t.spriteIcon[i].wpos,
                                        r = cc.v2(n).add(cc.v2(-100, 1300));
                                    EVUIEffView.emit(EVUIEffView.movePropSpriteIcon, n, r, t.spriteIcon[i].path, !0);
                                    EVUIEffView.emit(EVUIEffView.udpateMovePageTime);
                                    if (t.spriteIcon[i].isZb) {
                                        console.log(
                                            "ShopPageItem ----------------- 添加 装备 " + t.spriteIcon[i].count
                                        );
                                        for (var s = 0; s < t.spriteIcon[i].count; s++) {
                                            GameDataValue.addEquip(t.spriteIcon[i].idData);
                                            a.push({id: t.spriteIcon[i].idData, num: t.spriteIcon[i].count});
                                        }
                                    } else {
                                        var p = t.spriteIcon[i].idData;
                                        console.log(
                                            "ShopPageItem ----------------- 添加 资源 " +
                                                t.spriteIcon[i].idData +
                                                ">" +
                                                t.spriteIcon[i].count
                                        );
                                        if ("2" == p) {
                                            a.push({id: 1, num: t.spriteIcon[i].count});
                                            GameDataValue.setPropCount(
                                                c.PropKind.zhuanshi,
                                                GameDataValue.getPropCount(c.PropKind.zhuanshi) + t.spriteIcon[i].count
                                            );
                                        } else
                                            switch (p) {
                                                case "5":
                                                case "6":
                                                case "7":
                                                    a.push({id: p, num: t.spriteIcon[i].count});
                                                    GameDataValue.addRewardKind(p, t.spriteIcon[i].count);
                                            }
                                    }
                                }
                                PayData.addLog(o.resId, o.count, o.type, a, o.tip, o.tip2);
                                EVUIEffView.emit(EVUIEffView.closeShop);
                                t.closeUI();
                            }
                        },
                        e
                    );
                }
            };
            return n([l], e);
        })(r.default));
o.default = d;
